package offer.system;

import java.util.ArrayList;

import system.bean.Member;
import system.bean.Role;
import system.dao.RoleDao;

public class GetRoleSource {
	private static RoleDao roleDao = new RoleDao();
	
	public static boolean AddRole(Role bean){
		boolean success = false;
		if(!roleDao.isExist(bean)){
			success = roleDao.insert(bean);
		}
		return success;
	}
	
	public static boolean SaveRole(Role bean){
		boolean success = false;
		
		if(!roleDao.isExist(bean)){
			if(roleDao.checkRepeatForInsert(bean)){
				return false;
			}
			success = roleDao.insert(bean);
		}else{
			if(roleDao.checkRepeatForUpdate(bean)){
				return false;
			}
			success = roleDao.update(bean);
		}
		return success;
	}
	
	public static ArrayList<Object> getList(){
		String sql       =  "select * from " + Role.tableName ;
		String exception =  "GetRoleSource:function getList() has Error!"; 
		return roleDao.getList(sql, exception);
	}
	
	public static Role getRoleById(int roleId){
		
		return roleDao.getBeanById(roleId);
	}
	
	public static Role getRoleByIdentfy(String identify){
		
		return roleDao.getBeanByIdentify(identify);
	}
	
	public static boolean DeleteRoleByRoleId(int roleId){
		Role bean = new Role();
		bean.setRoleId(roleId);
		
		return roleDao.delete(bean);
	}
	
	
	
}
